
Const STR_PAD_LEFT:Int = 0;
Const STR_PAD_RIGHT:Int = 1;
Const STR_PAD_BOTH:Int = 2;

Rem
	This functions returns the input string padded on the left, the right, or both sides
	to the specified padding length. If the optional argument pad_string is not supplied,
	the input is padded with spaces, otherwise it is padded with characters from pad_string
	up to the limit.
	
	@author	Nicholas Grant
	@updatedby	
	
	@param	string	strinput
	@param	integer	pad_length
	@param	string	pad_string = " "
	@param	integer	pad_type = STR_PAD_RIGHT
	
	@variable	string	stringOutput
	@variable	integer	stringIndexMax
	@variable	integer	padding
	@variable	integer	padRight
	@variable	integer	cnt
	
	@return	string
End Rem
Function str_pad:String(strinput:String, pad_length:Int, pad_string:String = " ", pad_type:Int = STR_PAD_RIGHT)
	
	Local stringOutput:String = "";
	Local stringIndexMax:Int = pad_string.Length;
	
	If ( strinput.Length < pad_length )
		
		Local padding:Int = pad_length - strinput.Length;
		Local padRight:Int = 0;
		Local cnt:Int = 0;
		
		Select ( pad_type )
			
			Case 0
				
				For cnt = 0 To ( padding - 1 )
					stringOutput :+ substr( pad_string, cnt Mod stringIndexMax, 1 );
				Next
				
				stringOutput :+ strinput
				
			Case 1
				
				stringOutput :+ strinput;
				padRight = stringOutput.Length;
				
				For cnt = padRight To ( pad_length - 1 )
					stringOutput :+ substr( pad_string, cnt Mod stringIndexMax, 1 );
				Next
				
			Case 2
				
				For cnt = 0 To Floor( ( padding - 2 ) / 2.0 )
					stringOutput :+ substr( pad_string, cnt Mod stringIndexMax, 1 );
				Next
				
				stringOutput :+ strinput;
				padRight = stringOutput.Length;
				
				For cnt = padRight To ( pad_length - 1 )
					stringOutput :+ substr( pad_string, cnt Mod stringIndexMax, 1 );
				Next
				
		End Select
		
	Else
		stringOutput = strinput;
	End If
	
	Return stringOutput;
	
End Function